<?php
/**
 * CakeCMS后台 - 后台日志管理
 * 
 * @author zzdboy
 * @version 1.0
 */
class AdminLogs extends AppModel {
	public $name = 'AdminLogs';
	public $useTable = 'admin_logs';
	public $primaryKey = 'id';
	
	/**
	 * 根据日志ID获取日志相关信息
	 *
	 * @param int $id        	
	 */
	public function GetAdminRoleByID($id) {
		$LogsInfo = $this->find ( 'first', array (
				'conditions' => array (
						'id' => $id 
				) 
		) );
		return $LogsInfo;
	}
	
	/**
	 * 根据条件获取日志列表
	 *
	 * @param array $conditions        	
	 */
	public function GetAdminRoleByAll($conditions = array(), $limit = 10) {
		$result = array ();
		
		$result ['result'] = $this->find ( 'all', array (
				'conditions' => $conditions,
				'limit' => $limit,
				'order' => 'id DESC' 
		) );
		
		$result ['count'] = $this->find ( 'count', array (
				'conditions' => $conditions 
		) );
		
		return $result;
	}
	
	/**
	 * 添加日志
	 *
	 * @param array $data        	
	 * @return boolean
	 */
	public function add($data) {
		if (! is_array ( $data )) {
			return false;
		}
		$data ['AdminLogs'] ['create_time'] = date ( "Y-m-d H:i:s", time () );
		
		if ($this->save ( $data )) {
			return true;
		}
		return false;
	}
	
	/**
	 * 编辑日志
	 *
	 * @param array $data        	
	 */
	public function edit($data) {
		if (! is_array ( $data )) {
			return false;
		}
		
		if ($this->save ( $data )) {
			return true;
		}
		return false;
	}
	
	/**
	 * 删除日志
	 *
	 * @param int $id        	
	 */
	public function del($id) {
		if ($this->delete ( $id )) {
			return true;
		}
		return false;
	}
	
	/**
	 * 清空日志
	 */
	public function delAll() {
		if ($this->query ( "TRUNCATE TABLE db_admin_logs" )) {
			return true;
		}
		return false;
	}
}
?>